<template>
  <van-button
            v-if="isFollow"
            @click="Follow"
            :loading="isLoading"
            class="follow-btn"
            round
            size="small"
          >已关注</van-button>
    <van-button
            v-else
            @click="Follow"
            :loading="isLoading"
            class="follow-btn"
            type="info"
            color="#3296fa"
            round
            size="small"
            icon="plus"
            >关注</van-button>
</template>

<script>
import { getFollow, delFollow } from '@/api/user'
export default {
  data () {
    return {
      isLoading: false
    }
  },
  props: {
    isFollow: {
      type: Boolean,
      required: true
    },
    autId: {
      type: [String, Number, Object],
      required: true
    }
  },
  components: {},

  computed: {},
  methods: {
    async Follow () {
      this.isLoading = true
      try {
        if (this.isFollow) { // 为关注状态
          await delFollow(this.autId)
        } else {
          await getFollow(this.autId)
        }
        this.$emit('updateFollow', !this.isFollow)
      } catch (err) {
        if (err.response && err.response.status === 400) {
          this.$toast('用户不能关注自己')
        }
        console.log('其他错误', err)
      }
      this.isLoading = false
    }
  }
}
</script>

<style lang='less' scoped>
</style>
